package com.sample.thread.util;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import com.sample.thread.conf.ThreadPoolConfig;

/**
* @comments
* @author  zg
* @date 2021年3月13日
*/
@Component
public class AsyncTask {

    @Async(ThreadPoolConfig.THREAD_POOL_NAME)  //myTaskAsyncPool即配置线程池的方法名，此处如果不写自定义线程池的方法名，会使用默认的线程池
    public void doJob() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
                System.out.println(i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    
}
